package com.web;

import com.service.userService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 员工删除客户
 * 接收 userShow.jsp 页面的userId数据
 * 提交到 userService 的 deleteUserId 函数
 * 重定向到 /showUser
 */
@WebServlet("/deleteUser")
public class DeleteUserIdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.接收传入的id
        String id = request.getParameter("id");

        //2.删除数据
        new userService().deleteUserId(Integer.valueOf(id));
        System.out.println("删除了 id = " + id +" 的用户");

        //3.重定向
        response.sendRedirect(request.getContextPath()+"/showUser");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
